
var WSDataLoader = {
	curReques: null,
	data: null,

	getData: function()
	{
		//WSN_showNotification("WS Notice", "You click icon");
		WSInterface.setEvent("load");
		//WSInterface.setTooltip("hide");
		jsAssist.ajax({	callback: WSDataLoader.handleData,
				error: WSDataLoader.handleError,
				url: WSPref.conntype + "://" + WSPref.server + WSPref.dataPath,
				query: "uid=" + WSPref.currentUID,
				method: "post",
				remoteajax: true,
				typedata: "json"})
	},

	handleData: function(json)
	{
		WSN_LOG("data accepted: " + json);
		if(typeof json != "object")
		{
			WSN_LOG("incorrect data");
			return;
		}
		if(json.status === "logoff")
		{
			WSInterface.setEvent("loginerror");
			return;
		}
		if(json.status === "nochange")
		{
			WSInterface.setEvent("nonew");
			return;
		}
		if(!json.uid)
		{
			WSN_LOG("no uid");
			return;
		}
		if(WSPref.currentUID == json.uid)
		{
			WSN_LOG("missing 'nochange'");
			return;
		}
		WSPref.currentUID = json.uid;
		if(json.pathes)
		{
			if(json.pathes.lenght > 0)
				WSInterface.createPathes(json.pathes);
			else
				WSInterface.clearPathes();
		}

		if(json.events)
		{
			if(json.events.lenght > 0)
			{
				WSInterface.createTooltipGrid(json.pathes);
				WSInterface.setEvent("new");
			} else {
				WSInterface.clearTooltipGrid();
				WSInterface.setEvent("nonew");
			}
		}

		if(json.controls)
		{
			
		}

		if(json.linker)
		{
			if(json.linker.caption)
				caption = json.linker.caption;

			if(json.linker.label)
				label = json.linker.label;

			if(json.linker.href)
				href = json.linker.label;
		} 
		
		if((caption ||  label || href) && WSPref.showNotifyEveryTime)
		{
			WSN_showNotification(caption, label, href);
		}
	},

	handleError: function (errno)
	{
		WSInterface.setEvent("networkerror");
	}
}